package com.mk.cloud.common.domain;

import com.mk.cloud.common.enums.GlobalValues;
import org.osgl.util.S;import com.mk.cloud.common.util.S2;
import org.beetl.sql.core.annotatoin.AssignID;
import org.beetl.sql.core.annotatoin.Param;
import org.beetl.sql.core.annotatoin.Table;
import org.beetl.sql.core.mapper.BaseMapper;

import javax.persistence.Transient;
import java.io.Serializable;
import java.util.List;

@Table(name = "cp_user")
@SuppressWarnings("unused")
public class CpUser implements Serializable {
    @AssignID
    private String userid;
    
    @Transient
    private List<String> roleids;

    //电子邮箱
    private String email;
    //上次登录IP
    private String lastloginip;
    //上次登录地址
    private String lastloginplace;
    //上次登录时间
    private String lastlogintime;
    //密码
    private String password;
    //联系电话
    private String phone;
    //登录用户名
    private String username;
    //姓名
    private String realname;
    //注册时间
    private String regtime;
    //业务主键
    private String thrid;
    //头像
    private String userface;
    //用户备注
    private String userremark;
    //用户状态1正常0冻结
    private String userstate;
    //用户类型 0=平台,1=企业账号,2=仓库账号
    private String usertype;

    private String identityno;

    private String coid;
    private String isagent;//是否代理
    //所属企业
    @Transient
    private String coname;

    public CpUser() {
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUserCdid(){
        if(S.eq(this.usertype, GlobalValues.USERTYPE_2.value())){
            return this.thrid;
        }
        return null;
    }

    public String getIsagent() {
        return isagent;
    }

    public void setIsagent(String isagent) {
        this.isagent = isagent;
    }

    public String getCoid() {
        return coid;
    }

    public void setCoid(String coid) {
        this.coid = coid;
    }

    public String getConame() {
        return coname;
    }

    public void setConame(String coname) {
        this.coname = coname;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getLastloginip() {
        return lastloginip;
    }

    public void setLastloginip(String lastloginip) {
        this.lastloginip = lastloginip;
    }

    public String getLastloginplace() {
        return lastloginplace;
    }

    public void setLastloginplace(String lastloginplace) {
        this.lastloginplace = lastloginplace;
    }

    public String getLastlogintime() {
        return lastlogintime;
    }

    public void setLastlogintime(String lastlogintime) {
        this.lastlogintime = lastlogintime;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getRegtime() {
        return regtime;
    }

    public void setRegtime(String regtime) {
        this.regtime = regtime;
    }

    public String getThrid() {
        return thrid;
    }

    public void setThrid(String thrid) {
        this.thrid = thrid;
    }

    public String getUserface() {
        return userface;
    }

    public void setUserface(String userface) {
        this.userface = userface;
    }

    public String getUserremark() {
        return userremark;
    }

    public void setUserremark(String userremark) {
        this.userremark = userremark;
    }

    public String getUserstate() {
        return userstate;
    }

    public void setUserstate(String userstate) {
        this.userstate = userstate;
    }

    public String getUsertype() {
        return usertype;
    }

    public void setUsertype(String usertype) {
        this.usertype = usertype;
    }

    public List<String> getRoleids() {
        return roleids;
    }

    public void setRoleids(List<String> roleids) {
        this.roleids = roleids;
    }

    public String getIdentityno() {
        return identityno;
    }

    public void setIdentityno(String identityno) {
        this.identityno = identityno;
    }

    public interface Mapper extends BaseMapper<CpUser> {

        List<CpUser> login(@Param("username")String username, @Param("password")String password, @Param("usertype")String usertype);

        List<CpUser> login(@Param("username")String username, @Param("password")String password);

        /**
         * 通用
         * 重置密码，执行该方法前需要校验当前登录的用户是否拥有该权限，是否当前登录用户的子用户
         * @param userid
         * @param password
         * @return
         */
        int resetPwd(@Param("userid")String userid,@Param("password") String password);

        /**
         * 重置密码，根据用户手机号
         * @param phone
         * @param password
         * @return
         */
        int resetPasswordByPhone(@Param("phone")String phone,@Param("password") String password);

        /**
         * 查询当前用户是否和重置密码的用户属于同一个企业
         * @param userid
         * @param thrid 当前用户的所属公司
         * @return
         */
        String checkUserHavePower(@Param("userid")String userid,@Param("thrid")String thrid);

        /**
         * 根据手机号查询对应用户主键
         * @param phone
         * @return
         */
        String selectUserByPhone(@Param("phone") String phone);

        /**
         * 验证用户密码
         * @param userid
         * @param password
         * @return
         */
        String checkUserPwd(@Param("userid")String userid,@Param("password") String password);

        List<String> getRoleidList(@Param("userid")String userid);

    }

}